package com.allst.rmi.client;

import com.allst.rmi.demo.IHelloService;
import com.allst.rmi.pojo.User;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

/**
 * @author June
 * @since 2021年02月
 */
public class RMIClient {
    public static void main(String[] args) throws RemoteException, NotBoundException, MalformedURLException {
        // 1.从注册表中获取远程对象 , 强转
        IHelloService service = (IHelloService) Naming.lookup("rmi://127.0.0.1:9876/rmiServer");

        // 2.准备参数
        User user = new User("KangKang", 18);

        // 3.调用远程方法sayHello
        String message = service.sayHello(user);
        System.out.println(message);
    }
}
